// TextHandle.h: interface for the CTextHandle class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TEXTHANDLE_H__8F3E95C0_3043_4186_A5B0_55396968604E__INCLUDED_)
#define AFX_TEXTHANDLE_H__8F3E95C0_3043_4186_A5B0_55396968604E__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "MyConstants.h"

class CTextHandle  
{
	friend class CPsola;
public:
	CArray<UNITINFOFULL,UNITINFOFULL> DicSyllableArray;
	CArray<PHONESTRUCTINFO,PHONESTRUCTINFO> PhoneArray;
	CArray<PHONESTRUCTINFO,PHONESTRUCTINFO> InPhoneArray, MiPhoneArray,VoArray, FiPhoneArray;
	CArray<SYLLABLEFULL,SYLLABLEFULL> SylTextArray; // luu thong tin ve tat ca am tiet trong csdl text thaodv 100311
	CArray<UNITINFOFULL,UNITINFOFULL> SyllableArray; //chuyen tu dong 83 trong TextHandle.cpp
	
		
	SYLLABLEFULL SylTextElement; // luu thong tin ve 1 am tiet trong csdl text thaodv 100311

	void UpdateSylInfo(int index, SYLLABLESTRUCT Syllable);
	static CString GetLastError(int *nErrorCode = NULL);
	
	
	static CString CsDirectoryOfFile;
	static CString CS_DBFileName;
	static CString cs_DBSylTextFileName;
	CTextHandle();
	virtual ~CTextHandle();
	void CTextHandle::WriteToTextFile(CString cstr);
	BOOL CTextHandle::LoadSylTextData(CString csLocation);
	BOOL CTextHandle::SaveSylDB(CString cLine);
	CString NormalizeString(CString cstr);
	CArray<SYLLABLEFULL,SYLLABLEFULL> FindInTextDB(CString cstr, CArray<SYLLABLEFULL,SYLLABLEFULL> &SylTextArray);
	void CTextHandle::GetSylPosInTextDB(UNITINFOFULL &SyllableElement);
	void CTextHandle::GetSylArrayPosInTextDB(CArray<UNITINFOFULL, UNITINFOFULL> &SyllableArray);
		BOOL ParseText(CString &cs);

protected:
	BYTE EnergyModel(UNITINFOFULL Unit);
	BOOL ParseSylInfo(UNITINFOFULL &Syllable,SYLLABLESTRUCT *stSyl);
	BOOL ToneInPhrase(CArray<float, float> &F0Array, BYTE ToneType, float fNorF0, int nSylLen);
	void F0ContourGeneration(CArray<UNITINFOFULL, UNITINFOFULL> &SyllableArray);
	BOOL DurationModel(UNITINFOFULL Unit, float &Length, int &node);
	void LoadVowelAndTone();
	BOOL LoadPhoneme();
	void SyllableStructureAnalyse(UNITINFOFULL &SylOUT);
	BOOL LoadDictionary();
	BOOL SyllableAnalysis(UNITINFOFULL &DicSyllable);
	BOOL SyllableAnalysis(CString &csSyllable, UNITINFOFULL &DicSyllable);
	BOOL IsNumeric(LPCTSTR lpBuf,WORD nLen);
	static CString m_csError;
	BOOL ParseSylInfo(CString &cs,SYLLABLESTRUCT *stSyl);
	int GetSylCount();
	BOOL GetSylInfo(WORD wIndex,SYLLABLESTRUCT &stSyl);
	void Empty();
	void RemoveAt(int i);
	
	
	static int m_nErrorCode;
	//BOOL ParseText(CString &cs);
	CDWordArray m_pdwSyl;
	CStringArray VowelArray;
	CStringArray VowelNoToneArray;
	CByteArray ToneArray;
	float fRegister;
	float fSpeakingRate;
};

#endif // !defined(AFX_TEXTHANDLE_H__8F3E95C0_3043_4186_A5B0_55396968604E__INCLUDED_)
